package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.concurrent.CompletableFuture;

/**
 * createTime：2021/8/23 14:34
 * description：检查性异常
 */
public class ThrowsChecked {
    class Checked extends Exception {
    }

    static ThrowsChecked noChecked(ThrowsChecked tc) {
        return tc;
    }

    static ThrowsChecked withChecked(ThrowsChecked tc) throws Checked {
        return tc;
    }

    static void testCompletableFuture() {
        CompletableFuture.completedFuture(new ThrowsChecked())
                //开启线程执行没有异常捕获情况
                .thenApply(ThrowsChecked::noChecked)
                //有异常得情况来进行捕获
                .thenApply(tc -> {
                    try {
                        return withChecked(tc);
                    } catch (Checked c) {
                        throw new RuntimeException(c.getMessage());
                    }
                });
    }
}
